package com.ppch.wuwamanus.tools;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;

import java.io.IOException;

/**
 * Package:ppch-ai-agent
 * ClassName:FileOperationTool
 *
 * @Author 泡泡茶壶
 * @Create 2025/7/18 12:16
 * @Version 1.0
 * Description:
 *  网页抓取
 */
public class WebFetchTool {

    @Tool(description = "从指定URL地址抓取网页内容")
    public String fetchWebPage(@ToolParam(description = "要抓取网页的URL地址") String url) {
        try {
            Document doc = Jsoup.connect(url).get();
            return doc.html();
        } catch (IOException e) {
            return "网页抓取失败: " + e.getMessage();
        }
    }
}
